//turret.txt - Simple script for turrets
//Cell 0,1 - Stuff done flag. If both 0, nothing. Otherwise If non-zero, this 
//turret wont attack. If the turret is itself attacked, will set the not-attack setting back to 0.
//Cell 2,3 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

short i,target;
short talky = 0;
short last_abil;
short last_abil2;
short ae_mode = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Talis-Eye");
	set_boss_level(ME,2);
	last_abil = get_current_tick();
	last_abil2 = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(37,7,1);
	set_spec_item(52,1);
	begin_talk_mode(28);
break;

beginstate START_STATE; 
	if (who_shot_me() >= 0) {
		if (talky == 0) {
			talky = 1;
			begin_talk_mode(27);
			}

		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

		
	if (get_foe_target(ME,8,0)) {
		if (talky == 0) {
			talky = 1;
			begin_talk_mode(27);
			}

		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking

	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	

		if (char_ok(82) == FALSE) {
			spawn_creature(74);
			set_name(82,"Fresh Spawnling");
			}
			else if (char_ok(83) == FALSE) {
				spawn_creature(75);
				set_name(83,"Fresh Spawnling");
				}
			else if (char_ok(84) == FALSE) {
				spawn_creature(76);
				set_name(84,"Fresh Spawnling");
				}


	  	if (ae_mode == 0) { // debuff
		  	place_particle_num(ME,3,6,8);
			spray_missiles(43,8,8);
			print_named_str(ME,"radiates an aura of static.");
			pc_heard_sound_delay(201,250);						
			particle_nearby(8,8,2,4,2);
			status_nearby(-10,8,0,0);
			status_nearby(-10,8,8,0);
			status_nearby(-30,8,9,0);
			status_nearby(-30,8,11,0);
			status_nearby(-30,8,12,0);
			status_nearby(-30,8,13,0);
			status_nearby(-30,8,14,0);
			status_nearby(-30,8,15,0);
			status_nearby(-30,8,16,0);
			status_nearby(-30,8,18,0);
			status_nearby(-30,8,19,0);
	  		ae_mode = 1;
	  		}
	  	else if (ae_mode == 1) { // slow
		  	place_particle_num(ME,3,6,8);
			print_named_str(ME,"casts a slowing spell.");
			pc_heard_sound_delay(136,250);						
			status_nearby(-6,8,1,0);
	  		ae_mode = 2;
	  		}
	  	else if (ae_mode == 2) { // daze
		  	place_particle_num(ME,3,6,8);
			print_named_str(ME,"emits a dazing aura.");
			pc_heard_sound_delay(136,250);						
			status_nearby(get_level(ME) + 5 + get_attack_bonus(ME),8,17,0);
	  		ae_mode = 3;
	  		}
	  	else if (ae_mode == 3) { // charm
		  	place_particle_num(ME,3,6,8);
			spray_missiles(43,8,8);
			print_named_str(ME,"radiates an aura of weakness.");
			pc_heard_sound_delay(201,250);						
			particle_nearby(8,8,2,4,2);
			status_nearby(-10,8,0,0);
			status_nearby(-10,8,8,0);
	  		ae_mode = 1;
	  		}


		last_abil = get_current_tick();
		end();
		}

	if ((target_ok()) || (who_shot_me() >= 0)) {
		if (tick_difference(last_abil2,get_current_tick()) > 1) {
			run_char_animation(2,1,50);	
			pc_heard_sound_delay(136,100);						
			last_abil2 = get_current_tick();

			if (char_ok(85) == FALSE) {
				spawn_creature(77);
				set_level(85,20);
				place_particle_num(85,10,7,10);
				}
			else if (char_ok(86) == FALSE) {
				spawn_creature(78);
				set_level(86,20);
				place_particle_num(86,10,7,10);
				}
			else if (char_ok(87) == FALSE) {
				spawn_creature(79);
				set_level(87,22);
				place_particle_num(87,10,7,10);
				}
			else if (char_ok(88) == FALSE) {
				spawn_creature(80);
				set_level(88,24);
				place_particle_num(88,10,7,10);
				}
				
			if (char_ok(89) == FALSE) {
				spawn_creature(81);
				set_level(89,20);
				place_particle_num(89,10,7,10);
				}
			else if (char_ok(90) == FALSE) {
				spawn_creature(82);
				set_level(90,20);
				place_particle_num(90,10,7,10);
				}
			else if (char_ok(91) == FALSE) {
				spawn_creature(83);
				set_level(91,22);
				place_particle_num(91,10,7,10);
				}
			else if (char_ok(92) == FALSE) {
				spawn_creature(84);
				set_level(92,24);
				place_particle_num(92,10,7,10);
				}

			}
		}
		
	do_attack();

	turret_heal();
break;

beginstate TALKING_STATE;
	print_str("All it really is is a big fungus. It can't communicate at all.");
break;